<?php
namespace WebAdmin\Controller;
use WebAdmin\Controller\BaseController;
class ResumeDownloadController extends BaseController {
	
    public function index(){
    	$this->assign('page_title','简历下载列表');
    	$userModel = D("Users");
    	$list = $userModel->select();
    	$this->assign('list',$list);
    	$this->display();
    }

    //Ajax获取数据
    public function getData()
    {
        header("Content-type:text/html;charset=utf-8");
        $list=M('Users')->field('id,name,sex,age,mobile,xueli,create_time')->order('id desc')->select();
        //dump($list);exit;
        $this->ajaxReturn($list);
    }

    //单个简历下载
    public function download(){
        header("Content-type:text/html;charset=utf-8");
        $user_id=I('get.id');
        $user_info=M('Users')->where('id='.$user_id)->find();
        //dump($user_info);exit;
        echo '
<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<xml><w:WordDocument><w:View>Print</w:View></xml>
</head>';
        echo '<body>
<h1 style="text-align: center">'.$user_info['name'].'的简历</h1>
<h3>编号：'.$user_info['id'].'</h3>
<table border="1" cellpadding="3" cellspacing="0" >
<tr >
<td width="93" valign="center" colspan="2" >姓名</td>
<td width="160" valign="center" colspan="4" >'.$user_info['name'].'</td>
<td width="89" valign="center" colspan="2" >学历</td>
<td width="156" valign="center" colspan="3" >'.$user_info['xueli'].'</td>
<td width="125" colspan="2" rowspan="4" align="center" valign="middle" ><!--<img src="" width="120" height="120" />--></td>
</tr>
<tr >
<td width="93" valign="center" colspan="2" >性别</td>
<td width="72" valign="center" colspan="2" >'.$user_info['sex'].'</td>
<td width="88" valign="center" colspan="2" >出生年月</td>
<td width="89" valign="center" colspan="2" >'.$user_info['birthday'].'</td>
<td width="68" valign="center" >户籍地</td>
<td width="87" valign="center" colspan="2" >'.$user_info['huji'].'</td>
</tr>
<tr >
<td width="93" valign="center" colspan="2" >身高</td>
<td width="72" valign="center" colspan="2" >'.$user_info['height'].'cm</td>
<td width="88" valign="center" colspan="2" >体重</td>
<td width="89" valign="center" colspan="2" >'.$user_info['weight'].'kg</td>
<td width="68" valign="center" >婚姻状况</td>
<td width="87" valign="center" colspan="2" >'.$user_info['hunyin'].'</td>
</tr>
<tr >
<td width="93" valign="center" colspan="2" >手机</td>
<td width="160" valign="center" colspan="4" >'.$user_info['mobile'].'</td>
<td width="89" valign="center" colspan="2" >Email</td>
<td width="156" valign="center" colspan="3" >'.$user_info['email'].'</td>
</tr>
<tr >
<td width="93" valign="center" colspan="2"  style="width:93px;">家庭住址</td>
<td width="530" valign="center" colspan="11" >'.$user_info['address'].'</td>
</tr>
<tr >
<td width="93" valign="center" colspan="2" rowspan="3">求职意向</td>
<td width="93" valign="center" colspan="2">希望从事职业</td>
<td width="200" valign="center" colspan="2">'.$user_info['congshi'].'</td>
<td width="93" valign="center" colspan="2">希望薪资</td>
<td width="200" valign="center" colspan="5">'.$user_info['yuexin'].'元/月</td>
</tr>
<tr>
<td width="93" valign="center" colspan="2" >希望工作地区</td>
<td width="200" valign="center" colspan="2" >'.$user_info['diqu'].'</td>
<td width="93" valign="center" colspan="2" >食宿要求</td>
<td width="200" valign="center" colspan="5" >'.$user_info['shisu'].'</td>
</tr>
<tr>
<td width="93" valign="center" colspan="2" >目前状况</td>
<td width="200" valign="center" colspan="9" >'.$user_info['zhuangkuang'].'</td>
</tr>
<tr>
<td width="93" valign="center" >自我评价</td>
<td width="570" valign="center" colspan="12" >'.$user_info['pingjia'].'</td>
</tr>
<tr>
<td width="93" valign="center" >工作经历</td>
<td width="570" valign="center" colspan="12" >'.$user_info['gongzuojingli'].'</td>
</tr>
<tr>
<td width="93" valign="center" >教育经历</td>
<td width="570" valign="center" colspan="12" >'.$user_info['jiaoyujingli'].'</td>
</tr>
<tr>
<td width="93" valign="center" >培训经历</td>
<td width="570" valign="center" colspan="12" >'.$user_info['peixunjingli'].'</td>
</tr>
</table>
</body>';
        ob_start(); //打开缓冲区
        header("Cache-Control: public");
        Header("Content-type: application/octet-stream");
        Header("Accept-Ranges: bytes");
        if (strpos($_SERVER["HTTP_USER_AGENT"],'MSIE')) {
            header('Content-Disposition: attachment; filename='.$user_info['name'].'的简历.doc');
        }else if (strpos($_SERVER["HTTP_USER_AGENT"],'Firefox')) {
            Header('Content-Disposition: attachment; filename='.$user_info['name'].'的简历.doc');
        } else {
            header('Content-Disposition: attachment; filename='.$user_info['name'].'的简历.doc');
        }
        header("Pragma:no-cache");
        header("Expires:0");
        ob_end_flush();//输出全部内容到浏览器

    }



    public function add(){

        $PositionModel = D("Positions");

        if(!empty($_POST)) {
            $_POST['create_time'] = date('Y-m-d H:i:s');
            $_POST['update_time'] = date('Y-m-d H:i:s');

            $data = $PositionModel->create($_POST);
            $insert_id = $PositionModel->add($data);
            if($insert_id){
                header("Content-type: text/html; charset=utf-8");
                echo "<script>window.location.href='".__APP__."/index.php/Positions/';</script>";exit;
            }
        }

        $this->display();

    }

    public function edit(){
        $DataModel = D("Positions");
        if(!empty($_POST)) {
            $_POST['update_time'] = date('Y-m-d H:i:s');
            $DataModel->where("pos_id=".(int)$_POST['id'])->save($_POST);

            header("Content-type: text/html; charset=utf-8");
            echo "<script>window.location.href='".__APP__."/index.php/Positions/';</script>";exit;
        }else{
            $item = $DataModel->where("pos_id=".(int)$_GET['id'])->select();
            $this->assign('vo',$item[0]);
            $this->display();
        }
    }

    //单条记录删除
    public function delete(){
        if(!empty($_POST)) {
            $job_id=intval($_POST['job_id']);
            $result = M('UsersJobs')->delete($job_id);
            if($result){
                header("Content-type: text/html; charset=utf-8");
                echo "<script>layer.closeAll(); \$table.trigger(\"reloadGrid\");</script>";exit;
            }
        }
        $this->display();
    }


}